#include<bits/stdc++.h>
using namespace std;

int main() {
	int ret = 0;
	int n;
	cin >> n;
	int a[n + 10];
	
	int l = -1, r = -1;
	 
	for(int i = 1; i <= n; i ++ ) {
		int x;
		char f;
		cin >> a[i] >> f;
		if(f == 'L') {
			if(l == -1) {
				l = a[i];
			}
			ret += abs(a[i] - l);
			l = a[i];
		} else {
			if(r == -1) {
				r = a[i];
			}
			ret += abs(a[i] - r);
			r = a[i];
		}
	}
	
	cout << ret << endl;
	return 0;
}

